<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>RegModel.java</title>
<meta name="Generator" content="SciTE - www.Scintilla.org" />
<style type="text/css">
.S0 {
	color: #808080;
}
.S5 {
	font-weight: bold;
	color: #00007F;
}
.S6 {
	color: #7F007F;
}
.S10 {
	font-weight: bold;
	color: #000000;
}
span {
	font-family: 'Courier New';
	color: #000000;
	font-size: 9pt;
}
</style>
</head>
<body bgcolor="#FFFFFF">
<span><span class="S5">package</span><span class="S0"> </span>bbsimon<span class="S10">.</span>first<span class="S10">.</span>model<span class="S10">.</span>reg<span class="S10">;</span><br />
<br />
<span class="S5">import</span><span class="S0"> </span>java<span class="S10">.</span>io<span class="S10">.*;</span><br />
<span class="S5">import</span><span class="S0"> </span>java<span class="S10">.</span>util<span class="S10">.</span>regex<span class="S10">.*;</span><br />
<span class="S5">import</span><span class="S0"> </span>java<span class="S10">.</span>util<span class="S10">.*;</span><br />
<br />
<span class="S5">public</span><span class="S0"> </span><span class="S5">class</span><span class="S0"> </span>RegModel<span class="S0"> </span><span class="S10">{</span><br />
<span class="S0">&nbsp; &nbsp; &nbsp; &nbsp; </span><span class="S5">private</span><span class="S0"> </span><span class="S5">boolean</span><span class="S0"> </span>checkEmail<span class="S10">(</span>String<span class="S0"> </span>email<span class="S10">)</span><span class="S0"> </span><span class="S10">{</span><br />
<span class="S0">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span class="S5">return</span><span class="S0"> </span>Pattern<span class="S10">.</span>matches<span class="S10">(</span><span class="S6">"^[a-zA-Z]\\w*@\\w+\\.\\w{2,4}$"</span><span class="S10">,</span><span class="S0"> </span>email<span class="S10">);</span><br />
<span class="S0">&nbsp; &nbsp; &nbsp; &nbsp; </span><span class="S10">}</span><br />
<span class="S0">&nbsp; &nbsp; &nbsp; &nbsp; </span><span class="S5">private</span><span class="S0"> </span><span class="S5">boolean</span><span class="S0"> </span>checkPassword<span class="S10">(</span>String<span class="S0"> </span>password<span class="S10">)</span><span class="S0"> </span><span class="S10">{</span><br />
<span class="S0">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span class="S5">return</span><span class="S0"> </span>Pattern<span class="S10">.</span>matches<span class="S10">(</span><span class="S6">"^\\w{6,12}$"</span><span class="S10">,</span><span class="S0"> </span>password<span class="S10">);</span><br />
<span class="S0">&nbsp; &nbsp; &nbsp; &nbsp; </span><span class="S10">}</span><br />
<br />
<span class="S0">&nbsp; &nbsp; &nbsp; &nbsp; </span><span class="S5">public</span><span class="S0"> </span><span class="S5">void</span><span class="S0"> </span>reg<span class="S10">(</span>String<span class="S0"> </span>email<span class="S10">,</span><span class="S0"> </span>String<span class="S0"> </span>password<span class="S10">)</span><span class="S0"> </span><span class="S5">throws</span><span class="S0"> </span>Exception<span class="S0"> </span><span class="S10">{</span><br />
<span class="S0">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span class="S5">if</span><span class="S10">(</span>checkEmail<span class="S10">(</span>email<span class="S10">))</span><span class="S0"> </span><span class="S10">{</span><br />
<span class="S0">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span class="S5">if</span><span class="S10">(</span>checkPassword<span class="S10">(</span>password<span class="S10">))</span><span class="S0"> </span><span class="S10">{</span><br />
<span class="S0">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span>File<span class="S0"> </span>f<span class="S0"> </span><span class="S10">=</span><span class="S0"> </span><span class="S5">new</span><span class="S0"> </span>File<span class="S10">(</span><span class="S6">"regs"</span><span class="S10">);</span><br />
<span class="S0">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span>BufferedWriter<span class="S0"> </span>bw<span class="S0"> </span><span class="S10">=</span><span class="S0"> </span><span class="S5">new</span><span class="S0"> </span>BufferedWriter<span class="S10">(</span><span class="S5">new</span><span class="S0"> </span>FileWriter<span class="S10">(</span>f<span class="S10">,</span><span class="S0"> </span>true<span class="S10">));</span><br />
<span class="S0">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span>String<span class="S0"> </span>str<span class="S0"> </span><span class="S10">=</span><span class="S0"> </span>email<span class="S0"> </span><span class="S10">+</span><span class="S0"> </span><span class="S6">"|"</span><span class="S0"> </span><span class="S10">+</span><span class="S0"> </span>password<span class="S10">;</span><br />
<span class="S0">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span>bw<span class="S10">.</span>write<span class="S10">(</span>str<span class="S10">);</span><br />
<span class="S0">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span>bw<span class="S10">.</span>newLine<span class="S10">();</span><br />
<span class="S0">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span>bw<span class="S10">.</span>close<span class="S10">();</span><br />
<span class="S0">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span class="S10">}</span><br />
<span class="S0">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span class="S5">else</span><span class="S0"> </span><span class="S5">throw</span><span class="S0"> </span><span class="S5">new</span><span class="S0"> </span>Exception<span class="S10">(</span><span class="S6">"fail password checking"</span><span class="S10">);</span><br />
<span class="S0">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span class="S10">}</span><br />
<span class="S0">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span class="S5">else</span><span class="S0"> </span><span class="S5">throw</span><span class="S0"> </span><span class="S5">new</span><span class="S0"> </span>Exception<span class="S10">(</span><span class="S6">"fail email checking"</span><span class="S10">);</span><br />
<span class="S0">&nbsp; &nbsp; &nbsp; &nbsp; </span><span class="S10">}</span><br />
<br />
<span class="S0">&nbsp; &nbsp; &nbsp; &nbsp; </span><span class="S5">public</span><span class="S0"> </span>List<span class="S10">&lt;</span>String<span class="S10">&gt;</span><span class="S0"> </span>list<span class="S10">()</span><span class="S0"> </span><span class="S5">throws</span><span class="S0"> </span>IOException<span class="S0"> </span><span class="S10">{</span><br />
<span class="S0">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span>File<span class="S0"> </span>f<span class="S0"> </span><span class="S10">=</span><span class="S0"> </span><span class="S5">new</span><span class="S0"> </span>File<span class="S10">(</span><span class="S6">"regs"</span><span class="S10">);</span><br />
<span class="S0">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span>BufferedReader<span class="S0"> </span>br<span class="S0"> </span><span class="S10">=</span><span class="S0"> </span><span class="S5">new</span><span class="S0"> </span>BufferedReader<span class="S10">(</span><span class="S5">new</span><span class="S0"> </span>FileReader<span class="S10">(</span>f<span class="S10">));</span><br />
<span class="S0">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span>String<span class="S0"> </span>line<span class="S0"> </span><span class="S10">=</span><span class="S0"> </span><span class="S5">null</span><span class="S10">;</span><br />
<span class="S0">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span>List<span class="S10">&lt;</span>String<span class="S10">&gt;</span><span class="S0"> </span>all<span class="S0"> </span><span class="S10">=</span><span class="S0"> </span><span class="S5">new</span><span class="S0"> </span>ArrayList<span class="S10">&lt;</span>String<span class="S10">&gt;();</span><br />
<span class="S0">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span class="S5">while</span><span class="S10">((</span>line<span class="S0"> </span><span class="S10">=</span><span class="S0"> </span>br<span class="S10">.</span>readLine<span class="S10">())</span><span class="S0"> </span><span class="S10">!=</span><span class="S0"> </span><span class="S5">null</span><span class="S10">)</span><span class="S0"> </span><span class="S10">{</span><br />
<span class="S0">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span>all<span class="S10">.</span>add<span class="S10">(</span>line<span class="S10">);</span><br />
<span class="S0">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span class="S10">}</span><br />
<span class="S0">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span class="S5">return</span><span class="S0"> </span>all<span class="S10">;</span><br />
<span class="S0">&nbsp; &nbsp; &nbsp; &nbsp; </span><span class="S10">}</span><br />
<span class="S10">}</span><br />
<span class="S0"></span></span>
</body>
</html>
